package com.xunqi.ad.utils;

import com.xunqi.ad.exception.AdException;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.util.Date;

/**
 * @Description: 工具类
 * @Created with IntelliJ IDEA.
 * @author: 夏沫止水
 * @create: 2020-04-29 15:55
 **/
public class CommonUtils {

    //时间日期格式
    private static String[] parsePatterns = {
            "yyyy-MM-dd","yyyy/MM/dd","yyyy.MM.dd"
    };

    /**
     * 获取一个MD5
     * @param value
     * @return
     */
    public static String md5(String value) {

        return DigestUtils.md5DigestAsHex(value.getBytes(StandardCharsets.UTF_8));
    }

    public static Date parseStringDate(String dateString) throws AdException {

        try {
            return DateUtils.parseDate(dateString,parsePatterns);
        } catch (Exception e) {
            throw new AdException(e.getMessage());
        }

    }

}
